package cn.com;

import cn.com.ui.LifeBkActivity;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
/**
 * Tab 首页，用于添加包裹的消息
 * @author ChonZY
 */
public class HomeActivity extends ActivityGroup {
	private static LocalActivityManager manager ; 
	private RadioGroup radioGroup ;
	private static LinearLayout container ;
	public static Context context ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.home);
		context = this ;
		manager = getLocalActivityManager();
		initUI();
		
		container.removeAllViews();
		container.addView(manager.startActivity("PAGE_0", 
				new Intent(context, MsgActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
		
		radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.rb_tab_all: // 全部应用(添加的消息)
					container.removeAllViews();
					container.addView(manager.startActivity("PAGE_0", 
							new Intent(context, MsgActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
					
					
					break;
					
				case R.id.rb_tab_friends: // 好友
					container.removeAllViews();
					container.addView(manager.startActivity("PAGE_1", 
							new Intent(context, FriendsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
					break ;
				case R.id.rb_tab_setting: // 设置
					container.removeAllViews();
					container.addView(manager.startActivity("PAGE_2", 
							new Intent(context, SetActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
					break ;
					
				case R.id.rb_tab_lifebk:  // 生活百科
//					container.removeAllViews();
//					container.addView(manager.startActivity("PAGE_3", 
//							new Intent(context, LifeBkActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
					
					Intent intent = new Intent(HomeActivity.this, LifeBkActivity.class);
					startActivity(intent);
					break ;
					
				}
			}
		});
		
		
	}
	private void initUI() {
		container = (LinearLayout) findViewById(R.id.container);
		radioGroup = (RadioGroup) this.findViewById(R.id.rg_tab_group);
	}

}
